import {createStore} from "vuex"

export default createStore({
    state: {
        message: {},
        chat_id: 0,
        chat_list: {},
        addF: [],
        addTotal: 0,
        friendList: [],
        unRead: {},
        pTotal: []
    },
    mutations: {
        AddMessage(state, info) {
            state.message[info.id] = info.msgList
        },
        Change_id(state, id) {
            state.chat_id = id;
        },
        TMessage(state, data) {
            if (!state.message[data.target]) {
                state.message[data.target] = []
            }
            state.message[data.target].push(data)
            if (!state.message[data.from]) {
                state.message[data.from] = []
            }
            state.message[data.from].push(data)
        },
        AddChatList(state, info) {
            state.chat_list[info.id] = info.list
        },
        AddTotal(state, id) {
            state.pTotal.push(id)
        },
        ChangeListTotal(state,data){
            state.chat_list[data.id].unread++
            state.chat_list[data.id].content=data.content
            state.chat_list[data.id].time = data.time
        },
        ChangeList(state,data){
            state.chat_list[data.id].content=data.content
            state.chat_list[data.id].time = data.time
        }
    },
    actions: {},
    modules: {}
})